#### "Gender Inequality and Authoritarian Regimes" ####
# authors: "Lars Pelke"
# date: 2020-01-20

## use 01_data_wrangling before running this file 

## Set WD ##

#### Prepare Data for analysis ####

vdem <- vdem %>%
  drop_na(cown, year, gwf_type, gwf_type_mp)

vdem2 <- vdem %>%
  drop_na(cown, year, gwf_type, e_wb_pop_ln, e_migdppcln, e_total_resources_income_pc, eprratio)

vdem3 <- vdem %>%
  drop_na(cown, year, gwf_type, e_wb_pop_ln, e_migdppcln, e_total_resources_income_pc, eprratio, v2xps_party)

#### Computing group_mean and de-meaned variables ####

vdem2 <- sjmisc::de_mean(vdem2, e_wb_pop_ln, e_migdppcln, eprratio, e_total_resources_income_pc, 
                         grp = cown)

vdem3 <- sjmisc::de_mean(vdem3, e_wb_pop_ln, e_migdppcln, eprratio, e_total_resources_income_pc, v2xps_party,  
                         grp = cown)


#### Sample Supplementary Appendix ####
## Full Sample ##

sample1 <-vdem %>% 
  group_by(country_name) %>% 
  summarize(start = min(year), 
            end = max(year), 
            no_year = n())

sample1$start <- as.character(sample1$start)
sample1$end <- as.character(sample1$end)

cols1 <- c("country_name", "start", "end", "no_year")

library(stargazer)
stargazer(as.data.frame(sample1[, cols1]), type = "latex", summary = FALSE)

## Sample with Controls ##

sample2 <-vdem2 %>% 
  group_by(country_name) %>% 
  summarize(start = min(year), 
            end = max(year), 
            no_year = n())

sample2$start <- as.character(sample2$start)
sample2$end <- as.character(sample2$end)

cols1 <- c("country_name", "start", "end", "no_year")

library(stargazer)
stargazer(as.data.frame(sample2[, cols1]), type = "latex", summary = FALSE)


#### Additional Models for Sub Indicators ####

#comment: same models as in the main model, what is different is the depedent variable

#### Main Models, M1 - M4 DV: v2pepwrgen (Power distributed by Gender) ####

## Relevel Factor's ##
vdem$gwf_type <- as.factor(vdem$gwf_type)
vdem<- vdem %>% 
  mutate(gwf_type = relevel(gwf_type, "military"))

vdem$gwf_type_mp <- as.factor(vdem$gwf_type_mp)
vdem <- vdem %>% 
  mutate(gwf_type_mp = relevel(gwf_type_mp, "military regime"))

vdem2$gwf_type <- as.factor(vdem2$gwf_type)
vdem2 <- vdem2 %>% 
  mutate(gwf_type = relevel(gwf_type, "military"))

vdem2$gwf_type_mp <- as.factor(vdem2$gwf_type_mp)
vdem2 <- vdem2 %>% 
  mutate(gwf_type_mp = relevel(gwf_type_mp, "military regime"))


m1<- lmer(v2pepwrgen ~ year + gwf_type + 
            (1 + year | country_name), 
          data = vdem, 
          REML = TRUE)
sjstats::icc(m1)

m2 <- lmer(v2pepwrgen ~ year + gwf_type_mp + 
             (1 + year | country_name), 
           data = vdem, 
           REML = TRUE)

m3<- lmer(v2pepwrgen ~ year + gwf_type + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
            e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
            e_total_resources_income_pc_gm + 
            (1  + year | country_name), 
          data = vdem2, 
          REML = TRUE)
isSingular(m3, tol = 1e-05) # FALSE

m4<- lmer(v2pepwrgen ~ year + gwf_type_mp + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
            e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
            e_total_resources_income_pc_gm + 
            (1 + year | country_name), 
          data = vdem2, 
          REML = TRUE)


#### Extracting findings and plotting effects ####

tab_model(m1, m2, m3, m4,
          show.ci = FALSE, 
          show.se = TRUE, 
          auto.label = FALSE, 
          string.se = "SE",
          show.icc = FALSE, 
          dv.labels = c("Model 1", "Model 2", "Model 3", "Model 4"))

library(texreg)
texreg(list(m1, m2, m3, m4), 
       head.tag = TRUE, body.tag = TRUE,
       digits = 2,
       custom.coef.names = c("(Intercept)",
                             "Year",
                             "Communist Party Regime",
                             "Monarchy",
                             "Party Regime",
                             "Personal",
                             "Communist Regime",
                             "Communist Regime with MC", 
                             "Military Regime with MC", 
                             "Monarchy", 
                             "Monarchy with MC", 
                             "Party Regime", 
                             "Party Regime with MC", 
                             "Personal Regime", 
                             "Personal Regime with MC", 
                             "GDP pc log",
                             "GDP pc log (b)",
                             "Population log",
                             "Population log (b)",
                             "Ethnic Excluded Population", 
                             "Ethnic Excluded Population (b)", 
                             "Resource Income",
                             "Resource Income (b)"),
       booktabs = TRUE,
       use.packages = FALSE,
       caption = "Linear Within-Between Model Predicting Power distributed by Gender",
       fontsize = "scriptsize",
       stars = c(0.001, 0.01, 0.05, 0.1), 
       symbol = "\\dagger",
       label = "tab:tab-01", 
       longtable = TRUE)

## Relevel Factors ##
vdem3$gwf_type <- as.factor(vdem3$gwf_type)
vdem3 <- vdem3 %>% 
  mutate(gwf_type = relevel(gwf_type, "military"))

vdem3$gwf_type_mp <- as.factor(vdem3$gwf_type_mp)
vdem3 <- vdem3 %>% 
  mutate(gwf_type_mp = relevel(gwf_type_mp, "military regime"))


m5<- lmer(v2pepwrgen ~ year + gwf_type + v2xps_party_dm + v2xps_party_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m5, tol = 1e-05)

m6<- lmer(v2pepwrgen ~ year + gwf_type_mp + v2xps_party_dm + v2xps_party_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m6, tol = 1e-05)


m7 <- lmer(v2pepwrgen ~ year + gwf_type + v2xps_party_dm + v2xps_party_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
             e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
             e_total_resources_income_pc_gm + 
             (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
           data = vdem3, 
           REML = TRUE)
isSingular(m6, tol = 1e-05)

m8<- lmer(v2pepwrgen ~ year + gwf_type_mp + v2xps_party_dm + v2xps_party_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
            e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
            e_total_resources_income_pc_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m8, tol = 1e-05)

#### Texreg Findings ####

tab_model(m5, m6, m7, m8, 
          show.ci = FALSE, 
          show.se = TRUE, 
          auto.label = FALSE, 
          string.se = "SE",
          show.icc = FALSE, 
          dv.labels = c("Model 5", "Model 6", "Model 7", "Model 8"))

texreg(list(m5, m6, m7, m8), 
       head.tag = TRUE, body.tag = TRUE,
       digits = 2,
       custom.coef.names = c("(Intercept)",
                             "Year",
                             "Communist Party Regime",
                             "Monarchy",
                             "Party Regime",
                             "Personal",
                             "Party Institutionalization", 
                             "Party Institutionalization (b)", 
                             "Communist Regime",
                             "Communist Regime with MC", 
                             "Military Regime with MC", 
                             "Monarchy", 
                             "Monarchy with MC", 
                             "Party Regime", 
                             "Party Regime with MC", 
                             "Personal Regime", 
                             "Personal Regime with MC", 
                             "GDP pc log",
                             "GDP pc log (b)",
                             "Population log",
                             "Population log (b)",
                             "Ethnic Excluded Population", 
                             "Ethnic Excluded Population (b)", 
                             "Resource Income",
                             "Resource Income (b)"),
       booktabs = TRUE,
       use.packages = FALSE,
       caption = "Linear Within-Between Model Predicting Power Distributed by Gender",
       fontsize = "scriptsize",
       stars = c(0.001, 0.01, 0.05, 0.1), 
       symbol = "\\dagger",
       label = "tab:tab-01", 
       longtable = TRUE)

#### Main Models, M1 - M4 DV: v2clgencl (equality in respect for civil liberties by gender) ####

## Relevel Factor's ##
vdem$gwf_type <- as.factor(vdem$gwf_type)
vdem<- vdem %>% 
  mutate(gwf_type = relevel(gwf_type, "military"))

vdem$gwf_type_mp <- as.factor(vdem$gwf_type_mp)
vdem <- vdem %>% 
  mutate(gwf_type_mp = relevel(gwf_type_mp, "military regime"))

vdem2$gwf_type <- as.factor(vdem2$gwf_type)
vdem2 <- vdem2 %>% 
  mutate(gwf_type = relevel(gwf_type, "military"))

vdem2$gwf_type_mp <- as.factor(vdem2$gwf_type_mp)
vdem2 <- vdem2 %>% 
  mutate(gwf_type_mp = relevel(gwf_type_mp, "military regime"))


m1<- lmer(v2clgencl ~ year + gwf_type + 
            (1 + year | country_name), 
          data = vdem, 
          REML = TRUE)
isSingular(m1, tol = 1e-05) # FALSE
sjstats::icc(m1)

m2 <- lmer(v2clgencl ~ year + gwf_type_mp + 
             (1 + year | country_name), 
           data = vdem, 
           REML = TRUE)

m3<- lmer(v2clgencl ~ year + gwf_type + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
            e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
            e_total_resources_income_pc_gm + 
            (1  + year | country_name), 
          data = vdem2, 
          REML = TRUE)

m4<- lmer(v2clgencl ~ year + gwf_type_mp + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
            e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
            e_total_resources_income_pc_gm + 
            (1 + year | country_name), 
          data = vdem2, 
          REML = TRUE)


#### Extracting findings and plotting effects ####

tab_model(m1, m2, m3, m4,
          show.ci = FALSE, 
          show.se = TRUE, 
          auto.label = FALSE, 
          string.se = "SE",
          show.icc = FALSE, 
          dv.labels = c("Model 1", "Model 2", "Model 3", "Model 4"))

library(texreg)
texreg(list(m1, m2, m3, m4), 
       head.tag = TRUE, body.tag = TRUE,
       digits = 2,
       custom.coef.names = c("(Intercept)",
                             "Year",
                             "Communist Party Regime",
                             "Monarchy",
                             "Party Regime",
                             "Personal",
                             "Communist Regime",
                             "Communist Regime with MC", 
                             "Military Regime with MC", 
                             "Monarchy", 
                             "Monarchy with MC", 
                             "Party Regime", 
                             "Party Regime with MC", 
                             "Personal Regime", 
                             "Personal Regime with MC", 
                             "GDP pc log",
                             "GDP pc log (b)",
                             "Population log",
                             "Population log (b)",
                             "Ethnic Excluded Population", 
                             "Ethnic Excluded Population (b)", 
                             "Resource Income",
                             "Resource Income (b)"),
       booktabs = TRUE,
       use.packages = FALSE,
       caption = "Linear Within-Between Model Predicting Equality in Respect for Civil Liberties by Gender",
       fontsize = "scriptsize",
       stars = c(0.001, 0.01, 0.05, 0.1), 
       symbol = "\\dagger",
       label = "tab:tab-01", 
       longtable = TRUE)

## Model 5 - 8 ##

## Relevel Factors ##
vdem3$gwf_type <- as.factor(vdem3$gwf_type)
vdem3 <- vdem3 %>% 
  mutate(gwf_type = relevel(gwf_type, "military"))

vdem3$gwf_type_mp <- as.factor(vdem3$gwf_type_mp)
vdem3 <- vdem3 %>% 
  mutate(gwf_type_mp = relevel(gwf_type_mp, "military regime"))


m5<- lmer(v2clgencl ~ year + gwf_type + v2xps_party_dm + v2xps_party_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m5, tol = 1e-05)

m6<- lmer(v2clgencl ~ year + gwf_type_mp + v2xps_party_dm + v2xps_party_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m6, tol = 1e-05)


m7 <- lmer(v2clgencl ~ year + gwf_type + v2xps_party_dm + v2xps_party_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
             e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
             e_total_resources_income_pc_gm + 
             (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
           data = vdem3, 
           REML = TRUE)
isSingular(m6, tol = 1e-05)

m8<- lmer(v2clgencl ~ year + gwf_type_mp + v2xps_party_dm + v2xps_party_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
            e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
            e_total_resources_income_pc_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m8, tol = 1e-05)

#### Texreg Findings ####

tab_model(m5, m6, m7, m8, 
          show.ci = FALSE, 
          show.se = TRUE, 
          auto.label = FALSE, 
          string.se = "SE",
          show.icc = FALSE, 
          dv.labels = c("Model 5", "Model 6", "Model 7", "Model 8"))

texreg(list(m5, m6, m7, m8), 
       head.tag = TRUE, body.tag = TRUE,
       digits = 2,
       custom.coef.names = c("(Intercept)",
                             "Year",
                             "Communist Party Regime",
                             "Monarchy",
                             "Party Regime",
                             "Personal",
                             "Party Institutionalization", 
                             "Party Institutionalization (b)", 
                             "Communist Regime",
                             "Communist Regime with MC", 
                             "Military Regime with MC", 
                             "Monarchy", 
                             "Monarchy with MC", 
                             "Party Regime", 
                             "Party Regime with MC", 
                             "Personal Regime", 
                             "Personal Regime with MC", 
                             "GDP pc log",
                             "GDP pc log (b)",
                             "Population log",
                             "Population log (b)",
                             "Ethnic Excluded Population", 
                             "Ethnic Excluded Population (b)", 
                             "Resource Income",
                             "Resource Income (b)"),
       booktabs = TRUE,
       use.packages = FALSE,
       caption = "Linear Within-Between Model Predicting  Equality in Respect for Civil Liberties by Gender",
       fontsize = "scriptsize",
       stars = c(0.001, 0.01, 0.05, 0.1), 
       symbol = "\\dagger",
       label = "tab:tab-01", 
       longtable = TRUE)

#### Main Models, M1 - M4 DV: v2peapsgen (access to public services by gender) ####

m1<- lmer(v2peapsgen ~ year + gwf_type + 
            (1 + year | country_name), 
          data = vdem, 
          REML = TRUE)
isSingular(m1, tol = 1e-05) # FALSE
sjstats::icc(m1)

m2 <- lmer(v2peapsgen ~ year + gwf_type_mp + 
             (1 + year | country_name), 
           data = vdem, 
           REML = TRUE)
isSingular(m2, tol = 1e-05) # FALSE

m3<- lmer(v2peapsgen ~ year + gwf_type + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
            e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
            e_total_resources_income_pc_gm + 
            (1  + year | country_name), 
          data = vdem2, 
          REML = TRUE)

m4<- lmer(v2peapsgen ~ year + gwf_type_mp + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
            e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
            e_total_resources_income_pc_gm + 
            (1 + year | country_name), 
          data = vdem2, 
          REML = TRUE)
isSingular(m4, tol = 1e-05) # FALSE

#### Extracting findings and plotting effects ####

tab_model(m1, m2, m3, m4,
          show.ci = FALSE, 
          show.se = TRUE, 
          auto.label = FALSE, 
          string.se = "SE",
          show.icc = FALSE, 
          dv.labels = c("Model 1", "Model 2", "Model 3", "Model 4"))

library(texreg)
texreg(list(m1, m2, m3, m4), 
       head.tag = TRUE, body.tag = TRUE,
       digits = 2,
       custom.coef.names = c("(Intercept)",
                             "Year",
                             "Communist Party Regime",
                             "Monarchy",
                             "Party Regime",
                             "Personal",
                             "Communist Regime",
                             "Communist Regime with MC", 
                             "Military Regime with MC", 
                             "Monarchy", 
                             "Monarchy with MC", 
                             "Party Regime", 
                             "Party Regime with MC", 
                             "Personal Regime", 
                             "Personal Regime with MC", 
                             "GDP pc log",
                             "GDP pc log (b)",
                             "Population log",
                             "Population log (b)",
                             "Ethnic Excluded Population", 
                             "Ethnic Excluded Population (b)", 
                             "Resource Income",
                             "Resource Income (b)"),
       booktabs = TRUE,
       use.packages = FALSE,
       caption = "Linear Within-Between Model Predicting Access to Public Services by Gender",
       fontsize = "scriptsize",
       stars = c(0.001, 0.01, 0.05, 0.1), 
       symbol = "\\dagger",
       label = "tab:tab-01", 
       longtable = TRUE)

## Model 5 - 8 ##

m5<- lmer(v2peapsgen ~ year + gwf_type + v2xps_party_dm + v2xps_party_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m5, tol = 1e-05)

m6<- lmer(v2peapsgen ~ year + gwf_type_mp + v2xps_party_dm + v2xps_party_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m6, tol = 1e-05)


m7 <- lmer(v2peapsgen ~ year + gwf_type + v2xps_party_dm + v2xps_party_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
             e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
             e_total_resources_income_pc_gm + 
             (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
           data = vdem3, 
           REML = TRUE)
isSingular(m6, tol = 1e-05)

m8<- lmer(v2peapsgen ~ year + gwf_type_mp + v2xps_party_dm + v2xps_party_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
            e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
            e_total_resources_income_pc_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m8, tol = 1e-05)

#### Texreg Findings ####

tab_model(m5, m6, m7, m8, 
          show.ci = FALSE, 
          show.se = TRUE, 
          auto.label = FALSE, 
          string.se = "SE",
          show.icc = FALSE, 
          dv.labels = c("Model 5", "Model 6", "Model 7", "Model 8"))

texreg(list(m5, m6, m7, m8), 
       head.tag = TRUE, body.tag = TRUE,
       digits = 2,
       custom.coef.names = c("(Intercept)",
                             "Year",
                             "Communist Party Regime",
                             "Monarchy",
                             "Party Regime",
                             "Personal",
                             "Party Institutionalization", 
                             "Party Institutionalization (b)", 
                             "Communist Regime",
                             "Communist Regime with MC", 
                             "Military Regime with MC", 
                             "Monarchy", 
                             "Monarchy with MC", 
                             "Party Regime", 
                             "Party Regime with MC", 
                             "Personal Regime", 
                             "Personal Regime with MC", 
                             "GDP pc log",
                             "GDP pc log (b)",
                             "Population log",
                             "Population log (b)",
                             "Ethnic Excluded Population", 
                             "Ethnic Excluded Population (b)", 
                             "Resource Income",
                             "Resource Income (b)"),
       booktabs = TRUE,
       use.packages = FALSE,
       caption = "Linear Within-Between Model Predicting  Access to Public Services by Gender",
       fontsize = "scriptsize",
       stars = c(0.001, 0.01, 0.05, 0.1), 
       symbol = "\\dagger",
       label = "tab:tab-01", 
       longtable = TRUE)

#### Main Models, M1 - M4 DV: v2peasjgen (access to state jobs by gender) ####

m1<- lmer(v2peasjgen ~ year + gwf_type + 
            (1 + year | country_name), 
          data = vdem, 
          REML = TRUE)
isSingular(m1, tol = 1e-05) # FALSE
sjstats::icc(m1)

m2 <- lmer(v2peasjgen ~ year + gwf_type_mp + 
             (1 + year | country_name), 
           data = vdem, 
           REML = TRUE)
isSingular(m2, tol = 1e-05) # FALSE

m3<- lmer(v2peasjgen ~ year + gwf_type + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
            e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
            e_total_resources_income_pc_gm + 
            (1  + year | country_name), 
          data = vdem2, 
          REML = TRUE)

m4<- lmer(v2peasjgen ~ year + gwf_type_mp + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
            e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
            e_total_resources_income_pc_gm + 
            (1 + year | country_name), 
          data = vdem2, 
          REML = TRUE)
isSingular(m4, tol = 1e-05) # FALSE

#### Extracting findings and plotting effects ####

tab_model(m1, m2, m3, m4,
          show.ci = FALSE, 
          show.se = TRUE, 
          auto.label = FALSE, 
          string.se = "SE",
          show.icc = FALSE, 
          dv.labels = c("Model 1", "Model 2", "Model 3", "Model 4"))

library(texreg)
texreg(list(m1, m2, m3, m4), 
       head.tag = TRUE, body.tag = TRUE,
       digits = 2,
       custom.coef.names = c("(Intercept)",
                             "Year",
                             "Communist Party Regime",
                             "Monarchy",
                             "Party Regime",
                             "Personal",
                             "Communist Regime",
                             "Communist Regime with MC", 
                             "Military Regime with MC", 
                             "Monarchy", 
                             "Monarchy with MC", 
                             "Party Regime", 
                             "Party Regime with MC", 
                             "Personal Regime", 
                             "Personal Regime with MC", 
                             "GDP pc log",
                             "GDP pc log (b)",
                             "Population log",
                             "Population log (b)",
                             "Ethnic Excluded Population", 
                             "Ethnic Excluded Population (b)", 
                             "Resource Income",
                             "Resource Income (b)"),
       booktabs = TRUE,
       use.packages = FALSE,
       caption = "Linear Within-Between Model Predicting Access to State Jobs by Gender",
       fontsize = "scriptsize",
       stars = c(0.001, 0.01, 0.05, 0.1), 
       symbol = "\\dagger",
       label = "tab:tab-01", 
       longtable = TRUE)

## Model 5 - 8 ##

m5<- lmer(v2peasjgen ~ year + gwf_type + v2xps_party_dm + v2xps_party_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m5, tol = 1e-05)

m6<- lmer(v2peasjgen ~ year + gwf_type_mp + v2xps_party_dm + v2xps_party_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m6, tol = 1e-05)


m7 <- lmer(v2peasjgen ~ year + gwf_type + v2xps_party_dm + v2xps_party_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
             e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
             e_total_resources_income_pc_gm + 
             (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
           data = vdem3, 
           REML = TRUE)
isSingular(m6, tol = 1e-05)

m8<- lmer(v2peasjgen ~ year + gwf_type_mp + v2xps_party_dm + v2xps_party_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
            e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
            e_total_resources_income_pc_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m8, tol = 1e-05)

#### Texreg Findings ####

tab_model(m5, m6, m7, m8, 
          show.ci = FALSE, 
          show.se = TRUE, 
          auto.label = FALSE, 
          string.se = "SE",
          show.icc = FALSE, 
          dv.labels = c("Model 5", "Model 6", "Model 7", "Model 8"))

texreg(list(m5, m6, m7, m8), 
       head.tag = TRUE, body.tag = TRUE,
       digits = 2,
       custom.coef.names = c("(Intercept)",
                             "Year",
                             "Communist Party Regime",
                             "Monarchy",
                             "Party Regime",
                             "Personal",
                             "Party Institutionalization", 
                             "Party Institutionalization (b)", 
                             "Communist Regime",
                             "Communist Regime with MC", 
                             "Military Regime with MC", 
                             "Monarchy", 
                             "Monarchy with MC", 
                             "Party Regime", 
                             "Party Regime with MC", 
                             "Personal Regime", 
                             "Personal Regime with MC", 
                             "GDP pc log",
                             "GDP pc log (b)",
                             "Population log",
                             "Population log (b)",
                             "Ethnic Excluded Population", 
                             "Ethnic Excluded Population (b)", 
                             "Resource Income",
                             "Resource Income (b)"),
       booktabs = TRUE,
       use.packages = FALSE,
       caption = "Linear Within-Between Model Predicting Access to State Jobs by Gender",
       fontsize = "scriptsize",
       stars = c(0.001, 0.01, 0.05, 0.1), 
       symbol = "\\dagger",
       label = "tab:tab-01", 
       longtable = TRUE)

#### Main Models, M1 - M4 DV: v2peasbgen (access to state business opportunities by gender) ####

m1<- lmer(v2peasbgen ~ year + gwf_type + 
            (1 + year | country_name), 
          data = vdem, 
          REML = TRUE)
isSingular(m1, tol = 1e-05) # FALSE
sjstats::icc(m1)

m2 <- lmer(v2peasbgen ~ year + gwf_type_mp + 
             (1 + year | country_name), 
           data = vdem, 
           REML = TRUE)
isSingular(m2, tol = 1e-05) # FALSE

m3<- lmer(v2peasbgen ~ year + gwf_type + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
            e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
            e_total_resources_income_pc_gm + 
            (1  + year | country_name), 
          data = vdem2, 
          REML = TRUE)

m4<- lmer(v2peasbgen ~ year + gwf_type_mp + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
            e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
            e_total_resources_income_pc_gm + 
            (1 + year | country_name), 
          data = vdem2, 
          REML = TRUE)
isSingular(m4, tol = 1e-05) # FALSE

#### Extracting findings and plotting effects ####

tab_model(m1, m2, m3, m4,
          show.ci = FALSE, 
          show.se = TRUE, 
          auto.label = FALSE, 
          string.se = "SE",
          show.icc = FALSE, 
          dv.labels = c("Model 1", "Model 2", "Model 3", "Model 4"))

library(texreg)
texreg(list(m1, m2, m3, m4), 
       head.tag = TRUE, body.tag = TRUE,
       digits = 2,
       custom.coef.names = c("(Intercept)",
                             "Year",
                             "Communist Party Regime",
                             "Monarchy",
                             "Party Regime",
                             "Personal",
                             "Communist Regime",
                             "Communist Regime with MC", 
                             "Military Regime with MC", 
                             "Monarchy", 
                             "Monarchy with MC", 
                             "Party Regime", 
                             "Party Regime with MC", 
                             "Personal Regime", 
                             "Personal Regime with MC", 
                             "GDP pc log",
                             "GDP pc log (b)",
                             "Population log",
                             "Population log (b)",
                             "Ethnic Excluded Population", 
                             "Ethnic Excluded Population (b)", 
                             "Resource Income",
                             "Resource Income (b)"),
       booktabs = TRUE,
       use.packages = FALSE,
       caption = "Linear Within-Between Model Predicting Access to State Business Opportunities by Gender",
       fontsize = "scriptsize",
       stars = c(0.001, 0.01, 0.05, 0.1), 
       symbol = "\\dagger",
       label = "tab:tab-01", 
       longtable = TRUE)

## Model 5 - 8 ##

m5<- lmer(v2peasbgen ~ year + gwf_type + v2xps_party_dm + v2xps_party_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m5, tol = 1e-05)

m6<- lmer(v2peasbgen ~ year + gwf_type_mp + v2xps_party_dm + v2xps_party_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m6, tol = 1e-05)


m7 <- lmer(v2peasbgen ~ year + gwf_type + v2xps_party_dm + v2xps_party_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
             e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
             e_total_resources_income_pc_gm + 
             (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
           data = vdem3, 
           REML = TRUE)
isSingular(m6, tol = 1e-05)

m8<- lmer(v2peasbgen ~ year + gwf_type_mp + v2xps_party_dm + v2xps_party_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
            e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
            e_total_resources_income_pc_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m8, tol = 1e-05)

#### Texreg Findings ####

tab_model(m5, m6, m7, m8, 
          show.ci = FALSE, 
          show.se = TRUE, 
          auto.label = FALSE, 
          string.se = "SE",
          show.icc = FALSE, 
          dv.labels = c("Model 5", "Model 6", "Model 7", "Model 8"))

texreg(list(m5, m6, m7, m8), 
       head.tag = TRUE, body.tag = TRUE,
       digits = 2,
       custom.coef.names = c("(Intercept)",
                             "Year",
                             "Communist Party Regime",
                             "Monarchy",
                             "Party Regime",
                             "Personal",
                             "Party Institutionalization", 
                             "Party Institutionalization (b)", 
                             "Communist Regime",
                             "Communist Regime with MC", 
                             "Military Regime with MC", 
                             "Monarchy", 
                             "Monarchy with MC", 
                             "Party Regime", 
                             "Party Regime with MC", 
                             "Personal Regime", 
                             "Personal Regime with MC", 
                             "GDP pc log",
                             "GDP pc log (b)",
                             "Population log",
                             "Population log (b)",
                             "Ethnic Excluded Population", 
                             "Ethnic Excluded Population (b)", 
                             "Resource Income",
                             "Resource Income (b)"),
       booktabs = TRUE,
       use.packages = FALSE,
       caption = "Linear Within-Between Model Predicting Access to State Business Opportunities by Gender",
       fontsize = "scriptsize",
       stars = c(0.001, 0.01, 0.05, 0.1), 
       symbol = "\\dagger",
       label = "tab:tab-01", 
       longtable = TRUE)


###############################################################################################################
###############################################################################################################
###############################################################################################################

#### Disaggregating Party Institutionalization Effects on Women's Political Exclusion ####

vdem3 <- vdem %>%
  drop_na(cown, year, gwf_type, e_wb_pop_ln, e_migdppcln, e_total_resources_income_pc, eprratio, v2xps_party, 
          v2psorgs, v2psprbrch, v2psprlnks, v2psplats, v2pscohesv)

#### Computing group_mean and de-meaned variables ####

vdem3 <- sjmisc::de_mean(vdem3, e_wb_pop_ln, e_migdppcln, eprratio, e_total_resources_income_pc, v2xps_party, 
                         v2psorgs, v2psprbrch, v2psprlnks, v2psplats, v2pscohesv,
                         grp = cown)

## Relevel Factors ##
vdem3$gwf_type <- as.factor(vdem3$gwf_type)
vdem3 <- vdem3 %>% 
  mutate(gwf_type = relevel(gwf_type, "military"))

vdem3$gwf_type_mp <- as.factor(vdem3$gwf_type_mp)
vdem3 <- vdem3 %>% 
  mutate(gwf_type_mp = relevel(gwf_type_mp, "military regime"))

m5<- lmer(v2xpe_exlgender ~ year + gwf_type + v2xps_party_dm + v2xps_party_gm + 
            (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m5, tol = 1e-05)

m5.1 <- lmer(v2xpe_exlgender ~ year + gwf_type + v2psorgs_dm + v2psorgs_gm + 
            (1 + year | country_name) + (1 + v2psorgs_dm | country_name), 
          data = vdem3, 
          REML = TRUE)
isSingular(m5.1, tol = 1e-05)

m5.2 <- lmer(v2xpe_exlgender ~ year + gwf_type + v2psprbrch_dm + v2psprbrch_gm + 
              (1 + year | country_name) + (1 + v2psprbrch_dm | country_name), 
            data = vdem3, 
            REML = TRUE)

m5.3 <- lmer(v2xpe_exlgender ~ year + gwf_type + v2psprlnks_dm + v2psprlnks_gm + 
              (1 + year | country_name) + (1 + v2psprlnks_dm | country_name), 
            data = vdem3, 
            REML = TRUE)

m5.4 <- lmer(v2xpe_exlgender ~ year + gwf_type + v2psplats_dm + v2psplats_gm + 
              (1 + year | country_name) + (1 + v2psplats_dm | country_name), 
            data = vdem3, 
            REML = TRUE)
isSingular(m5.4, tol = 1e-05)

m5.5 <- lmer(v2xpe_exlgender ~ year + gwf_type + v2pscohesv_dm + v2pscohesv_gm + 
               (1 + year | country_name) + (1 + v2pscohesv_dm | country_name), 
             data = vdem3, 
             REML = TRUE)
isSingular(m5.5, tol = 1e-05)

m5.6 <- lmer(v2xpe_exlgender ~ year + gwf_type + v2psorgs_dm + v2psorgs_gm + v2psprbrch_dm + v2psprbrch_gm +
               v2psprlnks_dm + v2psprlnks_gm + v2psplats_dm + v2psplats_gm + v2pscohesv_dm + v2pscohesv_gm + 
               (1 + year | country_name) + (1 + v2psorgs_dm + v2psprbrch_dm + v2psprlnks_dm + v2psplats_dm + 
                                              v2pscohesv_dm| country_name), 
             data = vdem3, 
             REML = TRUE)


tab_model(m5, m5.1, m5.2, m5.3, m5.4, m5.5, m5.6,  
          show.ci = FALSE, 
          show.se = TRUE, 
          auto.label = FALSE, 
          string.se = "SE",
          show.icc = FALSE, 
          dv.labels = c("Model 5", "Model 5.1", "Model 5.2", "Model 5.3","Model 5.4", "Model 5.5", "Model 5.6" ))

texreg(list(m5, m5.1, m5.2, m5.3, m5.4, m5.5, m5.6), 
       head.tag = TRUE, body.tag = TRUE,
       digits = 2,
       custom.coef.names = c("(Intercept)",
                             "Year",
                             "Communist Party Regime",
                             "Monarchy",
                             "Party Regime",
                             "Personal",
                             "Party Institutionalization", 
                             "Party Institutionalization (b)", 
                             "Party Organizations",
                             "Party Organizations (b)", 
                             "Local branches", 
                             "Local branches (b)", 
                             "Constituency linkages", 
                             "Constituency linkages (b)", 
                             "Distinct platforms", 
                             "Distinct platforms (b)", 
                             "Legislative cohesiveness", 
                             "Legislative cohesiveness (b)"),
       booktabs = TRUE,
       use.packages = FALSE,
       caption = "Linear Within-Between Model Predicting Access to State Business Opportunities by Gender",
       fontsize = "scriptsize",
       stars = c(0.001, 0.01, 0.05, 0.1), 
       symbol = "\\dagger",
       label = "tab:tab-01", 
       longtable = TRUE)

#Model 7 #

m7 <- lmer(v2xpe_exlgender ~ year + gwf_type + v2xps_party_dm + v2xps_party_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
             e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
             e_total_resources_income_pc_gm + 
             (1 + year | country_name) + (1 + v2xps_party_dm | country_name), 
           data = vdem3, 
           REML = TRUE)

m7.1 <- lmer(v2xpe_exlgender ~ year + gwf_type + v2psorgs_dm + v2psorgs_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
               e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
               e_total_resources_income_pc_gm + 
               (1 + year | country_name) + (1 + v2psorgs_dm | country_name), 
             data = vdem3, 
             REML = TRUE)

m7.2 <- lmer(v2xpe_exlgender ~ year + gwf_type + v2psprbrch_dm + v2psprbrch_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
               e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
               e_total_resources_income_pc_gm + 
               (1 + year | country_name) + (1 + v2psprbrch_dm | country_name), 
             data = vdem3, 
             REML = TRUE)

m7.3 <- lmer(v2xpe_exlgender ~ year + gwf_type + v2psprlnks_dm + v2psprlnks_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
               e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
               e_total_resources_income_pc_gm + 
               (1 + year | country_name) + (1 + v2psprlnks_dm | country_name), 
             data = vdem3, 
             REML = TRUE)
isSingular(m7.3, tol = 1e-05)


m7.4 <- lmer(v2xpe_exlgender ~ year + gwf_type + v2psplats_dm + v2psplats_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
               e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
               e_total_resources_income_pc_gm + 
               (1 + year | country_name) + (1 + v2psplats_dm | country_name), 
             data = vdem3, 
             REML = TRUE)
isSingular(m7.4, tol = 1e-05)

m7.5 <- lmer(v2xpe_exlgender ~ year + gwf_type + v2pscohesv_dm + v2pscohesv_gm + e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
               e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
               e_total_resources_income_pc_gm + 
               (1 + year | country_name) + (1 + v2pscohesv_dm | country_name), 
             data = vdem3, 
             REML = TRUE)

m7.6 <- lmer(v2xpe_exlgender ~ year + gwf_type + v2psorgs_dm + v2psorgs_gm + v2psprbrch_dm + v2psprbrch_gm +
               v2psprlnks_dm + v2psprlnks_gm + v2psplats_dm + v2psplats_gm + v2pscohesv_dm + v2pscohesv_gm + 
               e_migdppcln_dm + e_migdppcln_gm + e_wb_pop_ln_dm +
               e_wb_pop_ln_gm +  eprratio_dm + eprratio_gm + e_total_resources_income_pc_dm + 
               e_total_resources_income_pc_gm + 
               (1 + year | country_name) + (1 + v2psorgs_dm + v2psprbrch_dm + v2psprlnks_dm + v2psplats_dm + 
                                              v2pscohesv_dm| country_name), 
             data = vdem3, 
             REML = TRUE)

tab_model(m7, m7.1, m7.2, m7.3, m7.4, m7.5, m7.6,  
          show.ci = FALSE, 
          show.se = TRUE, 
          auto.label = FALSE, 
          string.se = "SE",
          show.icc = FALSE, 
          dv.labels = c("Model 7", "Model 7.1", "Model 7.2", "Model 7.3","Model 7.4", "Model 7.5", "Model 7.6" ))

texreg(list(m7, m7.1, m7.2, m7.3, m7.4, m7.5, m7.6), 
       head.tag = TRUE, body.tag = TRUE,
       digits = 2,
       custom.coef.names = c("(Intercept)",
                             "Year",
                             "Communist Party Regime",
                             "Monarchy",
                             "Party Regime",
                             "Personal",
                             "Party Institutionalization", 
                             "Party Institutionalization (b)", 
                             "GDP pc log",
                             "GDP pc log (b)",
                             "Population log",
                             "Population log (b)",
                             "Ethnic Excluded Population", 
                             "Ethnic Excluded Population (b)", 
                             "Resource Income",
                             "Resource Income (b)",
                             "Party Organizations",
                             "Party Organizations (b)", 
                             "Local branches", 
                             "Local branches (b)", 
                             "Constituency linkages", 
                             "Constituency linkages (b)", 
                             "Distinct platforms", 
                             "Distinct platforms (b)", 
                             "Legislative cohesiveness", 
                             "Legislative cohesiveness (b)"),
       booktabs = TRUE,
       use.packages = FALSE,
       caption = "Linear Within-Between Model Predicting Access to State Business Opportunities by Gender",
       fontsize = "scriptsize",
       stars = c(0.001, 0.01, 0.05, 0.1), 
       symbol = "\\dagger",
       label = "tab:tab-01", 
       longtable = TRUE)

##################################################################################################
##################################################################################################

cluster_se <- function(model_result, data, cluster){
  model_variables   <- intersect(colnames(data), c(colnames(model_result$model), cluster))
  model_rows <- rownames(model_result$model) # changed to be able to work with mtcars, not tested with other data
  data <- data[model_rows, model_variables]
  cl <- data[[cluster]]
  M <- length(unique(cl))
  N <- nrow(data)
  K <- model_result$rank
  dfc <- (M/(M-1))*((N-1)/(N-K))
  uj  <- apply(estfun(model_result), 2, function(x) tapply(x, cl, sum));
  vcovCL <- dfc*sandwich(model_result, meat=crossprod(uj)/N)
}

#### Fixed Effects Regression ####

fe.1 <- felm(v2xpe_exlgender ~ gwf_type  | year + country_name,
          data = vdem)

fe.2 <- felm(v2xpe_exlgender ~  gwf_type_mp | year + country_name, 
           data = vdem)

fe.3 <- felm(v2xpe_exlgender ~  gwf_type + e_migdppcln_dm +  e_wb_pop_ln_dm +
            eprratio_dm +  e_total_resources_income_pc_dm | year + country_name, 
          data = vdem2)

fe.4 <- felm(v2xpe_exlgender ~  gwf_type_mp + e_migdppcln_dm +  e_wb_pop_ln_dm +
               eprratio_dm +  e_total_resources_income_pc_dm | year + country_name, 
             data = vdem2)



RSEfe.1 = coef(summary(fe.1, robust=TRUE))[,"Robust s.e"]
RpVlauefe.1 = coef(summary(fe.1, robust=TRUE))[,"Pr(>|t|)"]
RSEfe.2 = coef(summary(fe.2, robust=TRUE))[,"Robust s.e"]
RpVlauefe.2 = coef(summary(fe.2, robust=TRUE))[,"Pr(>|t|)"]
RSEfe.3 = coef(summary(fe.3, robust=TRUE))[,"Robust s.e"]
RpVlauefe.3 = coef(summary(fe.3, robust=TRUE))[,"Pr(>|t|)"]
RSEfe.4 = coef(summary(fe.4, robust=TRUE))[,"Robust s.e"]
RpVlauefe.4 = coef(summary(fe.4, robust=TRUE))[,"Pr(>|t|)"]


texreg(list(fe.1, fe.2, fe.3, fe.4), override.se = list(RSEfe.1, RSEfe.2, RSEfe.3, RSEfe.4),
       override.pvalues = list(RpVlauefe.1, RpVlauefe.2, RpVlauefe.3, RpVlauefe.4), 
       head.tag = TRUE, body.tag = TRUE,
       digits = 3,
       custom.coef.names = c("Communist Party Regime",
                             "Monarchy",
                             "Party Regime",
                             "Personal",
                             "Communist Regime",
                             "Communist Regime with MC", 
                             "Military Regime with MC", 
                             "Monarchy", 
                             "Monarchy with MC", 
                             "Party Regime", 
                             "Party Regime with MC", 
                             "Personal Regime", 
                             "Personal Regime with MC", 
                             "GDP pc log",
                             "Population log",
                             "Ethnic Excluded Population", 
                             "Resource Income"),
       booktabs = TRUE,
       use.packages = FALSE,
       caption = "Linear Fixed Effects Model prediciting Women's Political Exclusion",
       fontsize = "scriptsize",
       stars = c(0.001, 0.01, 0.05, 0.1), 
       symbol = "\\dagger",
       label = "tab:tab-01", 
       longtable = TRUE)

#### Fixed Effects Regression Model 5 - 8 ####

fe.5 <- felm(v2xpe_exlgender ~ gwf_type + v2xps_party_dm   | year + country_name,
             data = vdem3)

fe.6 <- felm(v2xpe_exlgender ~  gwf_type_mp + v2xps_party_dm| year + country_name, 
             data = vdem3)

fe.7 <- felm(v2xpe_exlgender ~  gwf_type + v2xps_party_dm + e_migdppcln_dm +  e_wb_pop_ln_dm +
               eprratio_dm +  e_total_resources_income_pc_dm | year + country_name, 
             data = vdem3)

fe.8 <- felm(v2xpe_exlgender ~  gwf_type_mp + v2xps_party_dm + e_migdppcln_dm +  e_wb_pop_ln_dm +
               eprratio_dm +  e_total_resources_income_pc_dm | year + country_name, 
             data = vdem3)



RSEfe.5 = coef(summary(fe.5, robust=TRUE))[,"Robust s.e"]
RpVlauefe.5 = coef(summary(fe.5, robust=TRUE))[,"Pr(>|t|)"]
RSEfe.6 = coef(summary(fe.6, robust=TRUE))[,"Robust s.e"]
RpVlauefe.6 = coef(summary(fe.6, robust=TRUE))[,"Pr(>|t|)"]
RSEfe.7 = coef(summary(fe.7, robust=TRUE))[,"Robust s.e"]
RpVlauefe.7 = coef(summary(fe.7, robust=TRUE))[,"Pr(>|t|)"]
RSEfe.8 = coef(summary(fe.8, robust=TRUE))[,"Robust s.e"]
RpVlauefe.8 = coef(summary(fe.8, robust=TRUE))[,"Pr(>|t|)"]


texreg(list(fe.5, fe.6, fe.7, fe.8), override.se = list(RSEfe.5, RSEfe.6, RSEfe.7, RSEfe.8),
       override.pvalues = list(RpVlauefe.5, RpVlauefe.6, RpVlauefe.7, RpVlauefe.8), 
       head.tag = TRUE, body.tag = TRUE,
       digits = 3,
       custom.coef.names = c("Communist Party Regime",
                             "Monarchy",
                             "Party Regime",
                             "Personal",
                             "Party Institutionalization",
                             "Communist Regime",
                             "Communist Regime with MC", 
                             "Military Regime with MC", 
                             "Monarchy", 
                             "Monarchy with MC", 
                             "Party Regime", 
                             "Party Regime with MC", 
                             "Personal Regime", 
                             "Personal Regime with MC", 
                             "GDP pc log",
                             "Population log",
                             "Ethnic Excluded Population", 
                             "Resource Income"),
       booktabs = TRUE,
       use.packages = FALSE,
       caption = "Linear Fixed Effects Model prediciting Women's Political Exclusion",
       fontsize = "scriptsize",
       stars = c(0.001, 0.01, 0.05, 0.1), 
       symbol = "\\dagger",
       label = "tab:tab-01", 
       longtable = TRUE)

###############################################################################################################
###############################################################################################################

#### Regime Data by Wahman, Teorell and Hadenius ####


